<?php

class PlanoDao extends Dao {

    public function injectDependencies() {

    }

    public function findAll() {
        $this->initConnection();
        $StSql = TQuery::getSqlListarPlanos();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArPlans = array();
        while ($ArPlanoData = mysqli_fetch_assoc($tQuery)) {
            $ArPlans[] = new Plano($ArPlanoData, $this->tMysqli);
        }
        $this->closeConnection();
        return $ArPlans;
    }

    public function findById($IDPlano) {
        $this->initConnection();
        $this->tMysqli->escape($IDPlano);
        $StSql = TQuery::getSqlFindPlansById($IDPlano);
        $tQuery = $this->tMysqli->exec($StSql);
        while ($ArPlanoData = mysqli_fetch_assoc($tQuery)) {
            $Plano = new Plano($ArPlanoData, $this->tMysqli);
        }
        $this->closeConnection();
        return isset($Plano) ? $Plano : false;
    }

    public function update($ArDados) {
        $this->initConnection();
        $this->tMysqli->escape($ArDados);
        $StSql = TQuery::getSqlUpdatePlans($ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function save($ArPlanoData) {
        $this->initConnection();
        $this->tMysqli->escape($ArPlanoData);
        $StSql = TQuery::getSqlInsertPlans($ArPlanoData);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function disable($IDPlano) {
        $this->initConnection();
        $this->tMysqli->escape($IDPlano);
        $StSql = TQuery::getSqlDisablePlan($IDPlano);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function enable($IDPlano) {
        $this->initConnection();
        $this->tMysqli->escape($IDPlano);
        $StSql = TQuery::getSqlEnablePlan($IDPlano);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function findEnabledPlans() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindEnabledPlans();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArPlans = array();
        while ($ArPlanoData = mysqli_fetch_assoc($tQuery)) {
            $ArPlans[] = new Plano($ArPlanoData, $this->tMysqli);
        }
        $this->closeConnection();
        return $ArPlans;
    }

}

?>
